package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.TbCompanies;
import com.ruoyi.system.service.ITbCompaniesService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 单位信息Controller
 * 
 * @author mcx
 * @date 2025-07-13
 */
@RestController
@RequestMapping("/system/companies")
public class TbCompaniesController extends BaseController
{
    @Autowired
    private ITbCompaniesService tbCompaniesService;

    /**
     * 查询单位信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:companies:list')")
    @GetMapping("/list")
    public TableDataInfo list(TbCompanies tbCompanies)
    {
        startPage();
        List<TbCompanies> list = tbCompaniesService.selectTbCompaniesList(tbCompanies);
        return getDataTable(list);
    }

    /**
     * 导出单位信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:companies:export')")
    @Log(title = "单位信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TbCompanies tbCompanies)
    {
        List<TbCompanies> list = tbCompaniesService.selectTbCompaniesList(tbCompanies);
        ExcelUtil<TbCompanies> util = new ExcelUtil<TbCompanies>(TbCompanies.class);
        util.exportExcel(response, list, "单位信息数据");
    }

    /**
     * 获取单位信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:companies:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(tbCompaniesService.selectTbCompaniesById(id));
    }

    /**
     * 新增单位信息
     */
    @PreAuthorize("@ss.hasPermi('system:companies:add')")
    @Log(title = "单位信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TbCompanies tbCompanies)
    {
        return toAjax(tbCompaniesService.insertTbCompanies(tbCompanies));
    }

    /**
     * 修改单位信息
     */
    @PreAuthorize("@ss.hasPermi('system:companies:edit')")
    @Log(title = "单位信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TbCompanies tbCompanies)
    {
        return toAjax(tbCompaniesService.updateTbCompanies(tbCompanies));
    }

    /**
     * 删除单位信息
     */
    @PreAuthorize("@ss.hasPermi('system:companies:remove')")
    @Log(title = "单位信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tbCompaniesService.deleteTbCompaniesByIds(ids));
    }
}
